import { makeAutoObservable } from "mobx";

export const cityConstants = {
  '北京市': 1,
  '上海市': 2,
};

class City {
  originCityName: keyof typeof cityConstants;
  cityName: keyof typeof cityConstants;
  cityId: number;

  constructor(_cityName: keyof typeof cityConstants) {
    makeAutoObservable(this);

    this.originCityName = _cityName;
    this.cityName = _cityName;
    this.cityId = cityConstants[_cityName];
  }

  setCityName(newCityName: keyof typeof cityConstants) {
    this.cityName = newCityName;
    this.cityId = cityConstants[newCityName];
    return this.cityName;
  }

  reset() {
    this.cityName = this.originCityName;
    this.cityId = cityConstants[this.originCityName];

    return { cityName: this.cityName };
  }
}

export default City;
